import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

/**
 * @type {function(app: import('koa').DefaultContext): void}
 */
export const createRoutes = async function (app) {
    for (const file of fs.readdirSync(__dirname)) {
        if (file === 'index.js') continue
        const router = await import(`./${file}`)
        const _router = router.default
        app.use(_router.routes())
        app.use(_router.allowedMethods())
    }
}
